import queryString from 'query-string'
import { removeProperty } from '@/utils/obj'

// 获取query
export const getURLQuery = () => {
  return queryString.parse(window.location.search)
}
// 把query拼入url
export const setURLQuery = (query = {}) => {
  const oldQuery = getURLQuery()
  const newQuery = { ...oldQuery, ...query }
  // 过滤空值
  const obj = removeProperty(newQuery)
  window.history.replaceState(null, '', `?${queryString.stringify(obj)}`)
  return newQuery
}

export default {
  getURLQuery,
  setURLQuery
}
